const invoke = window.__TAURI__.core.invoke;
// const event = window.__TAURI__.core.event;

export function server_list() {
    return invoke('server_list');
}

export function add_server(index, label, host, port, user, password) {
    return invoke('add_server', {
        index: index,
        label: label,
        host: host,
        port: port,
        user: user,
        password: password,
    });
}

export function del_server(index) {
    return invoke('del_server', {
        index: index
    });
}

export function sort_server(sort) {
    return invoke('sort_server', {
        sort: sort
    });
}

export function db_list(host, prot, user, password) {
    return invoke('db_list', {
        host: host,
        port: prot,
        user: user,
        password: password,
    });
}

export function execute_sql(host, database, sql, pagesize, page) {
    return invoke('execute_sql', {
        host: host,
        database: database,
        sql: sql,
        pagesize: pagesize ?? 20,
        page: page ?? 1,
    })
}

export function connect_db(host, port, user, password, database) {
    return invoke('connect_db', {
        host: host,
        port: port,
        user: user,
        password: password,
        database: database,
    })
}

export function create_table_preview(json) {
    return invoke('create_table_preview', {
        json: json,
    })
}

export function create_table(host, database, json) {
    return invoke('create_table', {
        host: host,
        database: database,
        json: json,
    })
}

export function alter_table_preview(json) {
    return invoke('alter_table_preview', {
        json: json,
    })
}

export function alter_table(host, database, json) {
    return invoke('alter_table', {
        host: host,
        database: database,
        json: json,
    })
}

export function table_columns(host, database, table, column) {
    return invoke('table_columns', {
        host: host,
        database: database,
        table: table,
        column: column ?? '',
    })
}

export function table_index(host, database, table) {
    return invoke('table_index', {
        host: host,
        database: database,
        table: table,
    })
}